import React, { Key } from "react";
import { Tree } from "antd";
import type { DataNode, TreeProps } from "antd/es/tree";
import { mainRoutes } from "@/router";
interface PropsType {
  onChange?: (
    arg:
      | {
          checked: Key[];
          halfChecked: Key[];
        }
      | Key[]
  ) => void;
}
const RoleTree: React.FC<PropsType> = (props) => {
  const onCheck: TreeProps["onCheck"] = (checkedKeys) => {
    console.log("onCheck", checkedKeys);
    if (props.onChange) {
      props.onChange(checkedKeys);
    }
  };

  return (
    <Tree
      checkable
      onCheck={onCheck}
      treeData={mainRoutes}
      fieldNames={{ title: "label" }}
    />
  );
};

export default RoleTree;
